﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace program16_D
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 绘直线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void butLine_Click(object sender, EventArgs e)
        {
            Graphics g=this.CreateGraphics();
            //创建画笔对象
            Pen pen = new Pen(Brushes.DarkRed);
            //线条风格
            pen.DashStyle = DashStyle.Dot;
            float[] dashValues = { 5, 2, 15, 4 };
            pen.DashPattern = dashValues;
            //画直线，建立坐标
            Point p1 = new Point(30, 50);
            Point p2 = new Point(300, 500);

            g.DrawLine(pen, p1, p2);
        }

        private void btnRect_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.BlueViolet);

            Size size = new Size(100, 80);
            Point startPoint = new Point(30, 30);
            Rectangle rect = new Rectangle(startPoint, size);

            g.DrawRectangle(pen, rect);

        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.Coral,6.0F);
            g.DrawEllipse(pen,90, 90,100,100);
        }

        private void btnPie_Click(object sender, EventArgs e)
        {
            //Graphics g = this.CreateGraphics();
            //Pen pen = new Pen(Brushes.DarkBlue, 6.0F);
            //g.DrawPie(pen, 50, 100, 200, 200, 45, 90);

            //pen  = new Pen(Brushes.Chartreuse, 6.0F);
            //g.DrawPie(pen, 50, 100, 200, 200, 135, 90);


            //填充
            Graphics g = this.CreateGraphics();
            SolidBrush bush = new SolidBrush(Color.Crimson);
            g.FillPie(bush, 50, 100, 200, 200, 45, 90);

            Color myColor = Color.FromArgb(255, 60, 200, 100);
            bush = new SolidBrush(myColor);
            g.FillPie(bush, 50, 100, 200, 200, 135, 90);

            //写字
            g.DrawString("年度业绩", new Font("微软雅黑", 12, FontStyle.Regular), Brushes.Black, new PointF(40, 300));
        }
        private int i = 0;
        //当窗体绘图时触发
        private void Form1_Load(object sender, EventArgs e)
        {
            i++;
            lblCount.Text = i.ToString();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            label1.Text = VaildateCode.CreateVCode(4);

            //把图片读入内存
            MemoryStream ms = new MemoryStream();
            ms.Write(VaildateCode.CreateVCdePicture(label1.Text), 0, VaildateCode.CreateVCdePicture(label1.Text).Length);
            //显示图片的文件流格式
            pb_vCode.Image = Image.FromStream(ms);
        }
    }
}
